﻿using System;
using System.Collections.Generic;
namespace WenSkin
{
    public class WenList<T> : List<T>
    {
        public event EventHandler<WenListEventArgs<T>> ItemAdded;
        public event EventHandler<WenListEventArgs<T>> ItemRemoved;
        protected virtual void OnItemAdded(T e, int index)
        {
            ItemAdded?.Invoke(this, new WenListEventArgs<T>(e, index));
        }
        protected virtual void OnItemRemoved(T e, int index)
        {
            ItemRemoved?.Invoke(this, new WenListEventArgs<T>(e, index));
        }
        public new void Add(T item)
        {
            base.Add(item);
            OnItemAdded(item, base.Count - 1);
        }
        public new void AddRange(IEnumerable<T> collection)
        {
            foreach (var item in collection)
            {
                Add(item);
            }
        }
        public new bool Remove(T item)
        {
            int index = base.IndexOf(item);
            OnItemRemoved(item, index);
            return base.Remove(item);
        }
        public new void RemoveAt(int index)
        {
            T t = base[index];
            OnItemRemoved(t, index);
            base.RemoveAt(index);
        }
    }

    public class WenListEventArgs<T> : EventArgs
    {
        public WenListEventArgs(T item, int index)
        {
            this.Item = item;
            this.Index = index;
        }

        public int Index { get; set; }

        public T Item { get; set; }
    }

}
